<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>XQuery</title><link rel="stylesheet" type="text/css" href="eclipse_book.css"><meta name="generator" content="DocBook XSL Stylesheets V1.77.1"><link rel="home" href="index.html" title="Red Hat Fuse Tooling"><link rel="up" href="RiderExLang.html" title="Part&nbsp;III.&nbsp;Expression and Predicates Languages"><link rel="prev" href="XPath.html" title="The XPath Language"><link rel="next" href="RiderEIPRef.html" title="Part&nbsp;IV.&nbsp;Enterprise Integration Pattern Reference"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="XQuery"></a>XQuery</h2></div></div></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33615"></a>Overview</h2></div></div></div><p>XQuery was originally devised as a query language for data stored in XML form in a
database. The XQuery language enables you to select parts of the current message, when the
message is in XML format. XQuery is a superset of the XPath language; hence, any valid XPath
expression is also a valid XQuery expression.</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33616"></a>Java syntax</h2></div></div></div><p>You can pass an XQuery expression to <code class="literal">xquery()</code> in several ways. For
simple expressions, you can pass the XQuery expressions as a string
(<code class="literal">java.lang.String</code>). For longer XQuery expressions, you might prefer to
store the expression in a file, which you can then reference by passing a
<code class="literal">java.io.File</code> argument or a <code class="literal">java.net.URL</code> argument to
the overloaded <code class="literal">xquery()</code> method. The XQuery expression implicitly acts on
the message content and returns a node set as the result. Depending on the context, the return
value is interpreted either as a predicate (where an empty node set is interpreted as false)
or as an expression.</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33617"></a>Adding the Saxon module</h2></div></div></div><p>To use XQuery in your routes you need to add a dependency on
<code class="literal">camel-saxon</code> to your project as shown in
<a class="xref" href="XQuery.html#ExPredLangXQueryEx060" title="Example&nbsp;22.&nbsp;Adding the camel-saxon dependency">Example&nbsp;22, &#8220;Adding the camel-saxon dependency&#8221;</a>.</p><div class="example"><a name="ExPredLangXQueryEx060"></a><p class="title"><b>Example&nbsp;22.&nbsp;Adding the camel-saxon dependency</b></p><div class="example-contents"><pre class="screen">&lt;!-- Maven POM File --&gt;
...
&lt;dependencies&gt;
  ...
  &lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-saxon&lt;/artifactId&gt;
    &lt;version&gt;${camel-version}&lt;/version&gt;
  &lt;/dependency&gt;
  ...
&lt;/dependencies&gt;</pre></div></div><br class="example-break"></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_camel_on_eap_deployment_3"></a>Camel on EAP deployment</h2></div></div></div><p>The <code class="literal">camel-saxon</code> component is supported by the Camel on EAP (Wildfly
Camel) framework, which offers a simplified deployment model on the Red Hat JBoss Enterprise Application Platform
(JBoss EAP) container.</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33618"></a>Static import</h2></div></div></div><p>To use the <code class="literal">xquery()</code> static method in your application code, include the
following import statement in your Java source files:</p><pre class="screen">import static org.apache.camel.component.xquery.XQueryBuilder.xquery;</pre></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33619"></a>Variables</h2></div></div></div><p><a class="xref" href="XQuery.html#XQueryAttTbl010" title="Table&nbsp;26.&nbsp;XQuery variables">Table&nbsp;26, &#8220;XQuery variables&#8221;</a> lists the variables that are accessible
when using XQuery.</p><div class="table"><a name="XQueryAttTbl010"></a><p class="title"><b>Table&nbsp;26.&nbsp;XQuery variables</b></p><div class="table-contents"><table summary="XQuery variables" border="1"><colgroup><col width="33%" class="col_1"><col width="33%" class="col_2"><col width="34%" class="col_3"></colgroup><thead><tr><th align="left" valign="top">Variable</th><th align="left" valign="top">Type</th><th align="left" valign="top">Description</th></tr></thead><tbody><tr><td align="left" valign="top"><p><code class="literal">exchange</code></p></td><td align="left" valign="top"><p><code class="literal">Exchange</code></p></td><td align="left" valign="top"><p>The current Exchange</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">in.body</code></p></td><td align="left" valign="top"><p><code class="literal">Object</code></p></td><td align="left" valign="top"><p>The body of the IN message</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">out.body</code></p></td><td align="left" valign="top"><p><code class="literal">Object</code></p></td><td align="left" valign="top"><p>The body of the OUT message</p></td></tr><tr><td align="left" valign="top"><p><code class="literal">in.headers.<span class="emphasis"><em>key</em></span></code></p></td><td align="left" valign="top"><p><code class="literal">Object</code></p></td><td align="left" valign="top"><p>The IN message header whose key is <span class="emphasis"><em>key</em></span></p></td></tr><tr><td align="left" valign="top"><p><code class="literal">out.headers.<span class="emphasis"><em>key</em></span></code></p></td><td align="left" valign="top"><p><code class="literal">Object</code></p></td><td align="left" valign="top"><p>The OUT message header whose key is <span class="emphasis"><em>key</em></span></p></td></tr><tr><td align="left" valign="top"><p><span class="emphasis"><em>key</em></span></p></td><td align="left" valign="top"><p><code class="literal">Object</code></p></td><td align="left" valign="top"><p>The Exchange property whose key is <span class="emphasis"><em>key</em></span></p></td></tr></tbody></table></div></div><br class="table-break"></div><div class="simplesect"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="topic-33620"></a>Example</h2></div></div></div><p><a class="xref" href="XQuery.html#ExPredLangXQueryEx090" title="Example&nbsp;23.&nbsp;Route using XQuery">Example&nbsp;23, &#8220;Route using XQuery&#8221;</a> shows a route that uses XQuery.</p><div class="example"><a name="ExPredLangXQueryEx090"></a><p class="title"><b>Example&nbsp;23.&nbsp;Route using XQuery</b></p><div class="example-contents"><pre class="screen">&lt;camelContext&gt;
  &lt;route&gt;
    &lt;from uri="activemq:MyQueue"/&gt;
    &lt;filter&gt;
      &lt;language langauge="xquery"&gt;/foo:person[@name='James']&lt;/language&gt;
      &lt;to uri="mqseries:SomeOtherQueue"/&gt;
    &lt;/filter&gt;
  &lt;/route&gt;
&lt;/camelContext&gt;</pre></div></div><br class="example-break"></div></div></body></html>